<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="">
    <title>My first blog post</title>
    <style>
        .p1 {
            position: relative;
            width: 50vw;
            height: 100px;
            background-color: aquamarine;
        }
        .p2 {
            background-color: blueviolet;
            width: 100px;
            position: absolute; 
            left: 50%;                  /*相对p1的宽度50%*/
        }
        .p3 {
            width: 50vw;
            height: 100px;
            background-color: bisque;
        }
        .p4 {
            background-color: blueviolet;
            width: 100px;
            position: absolute;
            left: 50%;                  /*相对body的宽度50%*/
        }
    </style>
</head>
<body>
    <div class="p1">
        <div class="p2">
            leihou
        </div>
    </div>
    <div class="p3">
            <div class="p4">
                leihou
            </div>
        </div>
</body>
</html>